package net.dodoman.sort;

public class MySorter {

	private static int[] array = { 2, 15, 18, 8, 3, 5, 7 };

	public static void main(String args[]) {
		// mpSort();
		xzSort();
		for (int i : array) {
			System.out.println(i);
		}
	}

	private static void swap(int i, int j) {
		int temp = array[i];
		array[i] = array[j];
		array[j] = temp;
	}

	/**
	 * 冒泡
	 */
	private static void mpSort() {
		for (int i = 0; i < array.length; i++) {
			for (int j = i + 1; j < array.length; j++) {
				if (array[i] > array[j]) {
					swap(i, j);
				}
			}
		}
	}

	/**
	 * 插入排序
	 */
	private static void xzSort() {
		for (int i = 0; i < array.length; i++) {
			int now = i;
			int frank = array[i];
			while (now > 0 && array[now - 1] <= frank) {
				array[now] = array[now - 1];
				now--;
			}
			array[now] = frank;

		}
	}
}
